package io.bluerain.contentprovider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

/**
 * Created by foredawn on 15-9-13.
 * ContentProvider小例子
 */
public class ContentProviderTest extends ContentProvider {

    @Override
    public boolean onCreate() {
        System.out.println("onCreate..");
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        print(uri);
        print("where:" + selection);
        print("args:" + selectionArgs);
        return null;
    }

    @Override
    public String getType(Uri uri) {
        print(uri);
        return uri.toString();
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        print(uri);
        print("values:" + values);
        return uri;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        print(uri);
        print("where:" + selection);
        print("args:" + selectionArgs);
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        print(uri);
        print("where:" + selection);
        print("args:" + selectionArgs);
        print("values:" + values);
        return 0;
    }

    public void print(Object obj) {
        System.out.print(obj);
        System.out.print("|");
    }
}
